class Solution {
public:
    int maxOperations(string s) {
        bool zero = false;
        int one = 0, cnt = 0;
        for (char c : s) {
            if (c == '0') zero = true;
            else {
                if (zero && one) cnt += one;
                one++;
                zero = false;
            }
        }
        if (s[s.size() - 1] == '0') cnt += one;
        return cnt;
    }
};